package com.wtgroup.demo.mianshi.容器.链表;

import com.wtgroup.demo.common.bean.LinkNode;

/**
 * @author dafei
 * @version 0.1
 * @date 2021/4/16 16:14
 */
public class D3_删除给定值 {
    public static void main(String[] args) {
        LinkNode linkNode = LinkNode.toListNode(1);

        LinkNode res = run(linkNode, 91);
        LinkNode.print(res);
    }

    public static LinkNode run(LinkNode head, int rmVal) {
        LinkNode dummyHead = new LinkNode();
        dummyHead.next = head;
        LinkNode prev = dummyHead;
        LinkNode cur;
        while (prev.next != null) {
            cur = prev.next;
            if (cur.value == rmVal) {
                prev.next = cur.next;
            } else {
                prev = cur;
            }
        }

        return dummyHead.next;
    }

}
